// import { Switch, Route, Redirect } from 'react-router-dom'
// import React, {Component} from 'react'
// class Index extends Component {
//     render() {
//         const routes = this.props.routes
//         return <Switch>
//             { routes.map((item, index) => {
//                 if(item.type === 'route') {
//                     return <Route key={index} path={item.path} render={props=> {
//                         return <item.component routes={item.children} {...{...this.props, ...props}}></item.component>
//                     }}></Route>
//                 } else {
//                     return <Redirect key={index} from={item.from} to={item.to}></Redirect>
                    
//                 }
//             })}
//         </Switch>
//     }
// }
// export default Index

import React, {Component} from 'react'
import { Switch, Route, Redirect } from 'react-router-dom'
export default class Index extends Component {
    render() {
        const {routes} = this.props
        const normalRoutes = routes.filter(item => !item.to)
        const redirectRoutes = routes.filter(item => item.from).map((item, key) => <Redirect key={key} from={item.from} to={item.to}></Redirect>)
        return(
            <Switch>
                {
                    normalRoutes && normalRoutes.map((item, key) => <Route key={key} path={item.path} 
                        render={props => <item.component {...props} routes={item.children}></item.component>}></Route>).concat(redirectRoutes)
                }
            </Switch>
        )
    }
}